package router

import (
	"api"
	"service"
	"dao"
	"github.com/gin-gonic/gin"
	"conf"
)

func NewRouter() *gin.Engine {

	r := gin.Default()

	adminApi := api.NewAdminApi(service.NewAdminService(dao.NewAdminDao(conf.DB)))
	orderApi := api.NewOrderApi(service.NewOrderService(dao.NewOrderDao(conf.DB)))
	newsApi := api.NewNewsApi(service.NewNewsService(dao.NewNewsDao(conf.DB)))
	userApi := api.NewUserApi(service.NewUserService(dao.NewUserDao(conf.DB)))
	advApi := api.NewAdvApi(service.NewAdvService(dao.NewAdvDao(conf.DB)))
	categoryApi := api.NewCategoryApi(service.NewCategoryService(dao.NewCategoryDao(conf.DB)))
	goodsApi := api.NewGoodsApi(service.NewGoodsService(dao.NewGoodsDao(conf.DB)))

	adminV1 := r.Group("/admin/api/v1")
	{
		// 登录接口
		adminV1.POST("/login", adminApi.Login)
		// 保存管理员接口
		adminV1.POST("/admins", adminApi.Insert)
		// 根据ID修改管理员接口
		adminV1.PUT("/admins/:id", adminApi.Update)
		// 根据ID删除管理员接口
		adminV1.DELETE("/admins/:id", adminApi.Delete)
		// 管理员查询接口
		adminV1.GET("/admins", adminApi.List)

		// 分页查询新闻
		adminV1.GET("/news", newsApi.List)
		// 根据ID删除新闻
		adminV1.DELETE("/news/:id", newsApi.Delete)
		// 根据ID查询新闻
		adminV1.GET("/news/:id", newsApi.Find)
		// 根据id更新新闻
		adminV1.PUT("/news/:id", newsApi.Update)
		// 添加新闻信息
		adminV1.POST("/news", newsApi.Insert)

		// 分页查询客户
		adminV1.GET("/users", userApi.List)
		// 根据Id删除客户
		adminV1.DELETE("/users/:id", userApi.Delete)
		// 根据Id查询客户信息
		adminV1.GET("/users/:id", userApi.Find)

		// 分页查询广告
		adminV1.GET("/advs", advApi.List)
		// 根据ID删除广告
		adminV1.DELETE("/advs/:id", advApi.Delete)
		// 添加广告信息
		adminV1.POST("/advs", advApi.Insert)
		// 根据ID查询广告
		adminV1.GET("/advs/:id", advApi.Find)
		// 根据ID修改广告
		adminV1.PUT("/advs/:id", advApi.Update)

		// 分类查询
		adminV1.GET("/categories", categoryApi.List)
		// 根据ID删除分类信息
		adminV1.DELETE("/categories/:id", categoryApi.Delete)
		// 根据ID查询分类信息
		adminV1.GET("/categories/:id", categoryApi.Find)
		// 查询所有父级分类
		adminV1.GET("/category", categoryApi.ListParents)
		// 添加分类
		adminV1.POST("/categories", categoryApi.Insert)
		// 修改分类
		adminV1.PUT("/categories/:id", categoryApi.Update)

		// 分页查询商品
		adminV1.GET("/goods", goodsApi.List)
		// 根据ID删除商品
		adminV1.DELETE("/goods/:id", goodsApi.Delete)
		// 根据ID查询商品
		adminV1.GET("/goods/:id", goodsApi.Find)
		// 根据id更新商品
		adminV1.PUT("/goods/:id", goodsApi.Update)
		// 添加商品信息
		adminV1.POST("/goods", goodsApi.Insert)

		//上传接口
		adminV1.Any("/upload", api.GetUploadToken)
	}

	orderV1 := r.Group("/order/api/v1")
	{
		// 保存订单接口
		orderV1.POST("/create", orderApi.Insert)
	}

	return r

}
